/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.controller;

import com.bayu.services.dao.AvgStopTimeDao;
import com.bayu.services.dao.CompDao;
import com.bayu.services.dao.ExchangeCurrencyImpl;
import com.bayu.services.dao.Graph2mlDao;
import com.bayu.services.dao.GraphCsHollowDao;
import com.bayu.services.dao.GraphDisaDao;
import com.bayu.services.dao.GraphPmsDao;
import com.bayu.services.dao.GraphSm60Dao;
import com.bayu.common.lib.CommonUtil;
import com.bayu.services.dao.AverageMouldingDao;
import com.bayu.services.dao.AvgMouldingDao;
import com.bayu.services.dao.AvgOdcDao;
import com.bayu.services.dao.CompDao;
import com.bayu.services.dao.ExchangeCurrencyImpl;
import com.bayu.services.dao.ExchangeRateDao;
import com.bayu.services.dao.K3Dao;
import com.bayu.services.dao.KecelakaanKerjaDao;
import com.bayu.services.dao.ListrikDao;
import com.bayu.services.dao.NewItemDao;
import com.bayu.services.dao.NotereportDao;
import com.bayu.services.dao.OdcDao;
import com.bayu.services.dao.PfDao;
import com.bayu.services.dao.PfrekapDao;
import com.bayu.services.dao.PreInspectionDao;
import com.bayu.services.dao.RejectCastingDao;
import com.bayu.services.dao.RejectGalvaImpl;
import com.bayu.services.dao.RejectMachiningDao;
import com.bayu.services.dao.RekapKecelakaanKerjaDao;
import com.bayu.services.dao.StockDao;
import com.bayu.services.dao.StockMonthDao;
import com.bayu.services.dao.TIncomingUsageDao;
import com.bayu.services.dao.TRejectionMouldDao;
import com.bayu.services.dao.TRejectionMouldPmsDao;
import com.bayu.services.dao.TRejectionMouldSSMDao;
import com.bayu.services.dao.TRejectionMouldSm60Dao;
import com.bayu.services.dao.TRejectionMouldDisaDao;
import com.bayu.services.dao.TRejectionMouldHollowDao;
import com.bayu.services.dao.TStockDao;
import com.bayu.services.dao.TdqDao;
import com.bayu.services.entity.AverageMoulding;
import com.bayu.services.entity.AvgMoulding;
import com.bayu.services.entity.AvgStopTime;
import com.bayu.services.entity.Avgodc;
import com.bayu.services.entity.TRejectionMouldDisa;
import com.bayu.services.entity.Comp;
import com.bayu.services.entity.ExchangeCurrency;
import com.bayu.services.entity.ExchangeRate;
import com.bayu.services.entity.K3;
import com.bayu.services.entity.Listrik;
import com.bayu.services.entity.Pf;
import com.bayu.services.entity.Pfrekap;
import com.bayu.services.entity.Preinspection;
import com.bayu.services.entity.RejectCasting;
import com.bayu.services.entity.RejectGalva;
import com.bayu.services.entity.RejectMachining;
import com.bayu.services.entity.Stock;
import com.bayu.services.entity.TRejectionMould;
import com.bayu.services.entity.TRejectionMouldHollow;
import com.bayu.services.entity.TRejectionMouldPms;
import com.bayu.services.entity.TRejectionMouldSm60;
import com.bayu.services.entity.TRejectionMouldSsm;
import com.bayu.services.entity.NewItem;
import com.bayu.services.entity.Tdq;
import com.bayu.services.entity.Graph2ml;
import com.bayu.services.entity.GraphCsHollow;
import com.bayu.services.entity.GraphDisa;
import com.bayu.services.entity.GraphPms;
import com.bayu.services.entity.GraphSm60;
import com.bayu.services.entity.Notereport;
import com.bayu.services.entity.KecelakaanKerja;
import com.bayu.services.entity.RekapKecelakaanKerja;
import com.bayu.services.entity.Odc;
import com.bayu.services.entity.TIncomingUsage;
import com.bayu.services.entity.TStock;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 *
 * @author Bayu
 */
@Controller
public class MainController {
    public static String month;
    public static String year;
    public static String startDate;
    public static String endDate;
    public static String type;
    


    ExchangeCurrencyImpl exchangeCurrencyDao;
    RejectGalvaImpl rejectGalvaDao;
    RejectCastingDao rejectCastingDao;
    RejectMachiningDao rejectMachiningDao;
    PreInspectionDao preInspectionDao;
    CompDao compDao;
    PfDao pfDao;
    ListrikDao listrikDao;
    PfrekapDao pfrekapDao;
    K3Dao k3Dao;
    StockDao sSDao;
    TRejectionMouldDao rejectionMouldDao;
    TRejectionMouldSSMDao tRejectionMouldSSMDao;
    TRejectionMouldPmsDao tRejectionMouldPmsDao;
    TRejectionMouldSm60Dao tRejectionMouldSm60Dao;
    TRejectionMouldDisaDao tRejectionMouldDisaDao;
    TRejectionMouldHollowDao tRejectionMouldHollowDao;
    NewItemDao newItemDao;
    TdqDao tdqDao;
	GraphPmsDao graphPmsDao;
    GraphSm60Dao graphSm60Dao;
    Graph2mlDao graph2mlDao;
    AvgStopTimeDao avgStopTimeDao;
    GraphCsHollowDao graphCsHollowDao;
    GraphDisaDao graphDisaDao;
    ExchangeRateDao exchangeRateDao;
    NotereportDao notereportDao;
    TIncomingUsageDao tIncomingUsageDao;
    TStockDao stockDao;
    OdcDao odcDao;
    AvgOdcDao avgOdcDao;
    // Fikri, 20 Juni 2011
    AvgMouldingDao avgMouldingDao;
    AverageMouldingDao averageMouldingDao;
    KecelakaanKerjaDao kecelakaanKerjaDao;
    RekapKecelakaanKerjaDao rekapKecelakaanKerjaDao;

    @Autowired
    public void setRekapKecelakaanKerjaDao(RekapKecelakaanKerjaDao rekapKecelakaanKerjaDao) {
        this.rekapKecelakaanKerjaDao = rekapKecelakaanKerjaDao;
    }

    @Autowired
    public void setKecelakaanKerjaDao(KecelakaanKerjaDao kecelakaanKerjaDao) {
        this.kecelakaanKerjaDao = kecelakaanKerjaDao;
    }
    // Fikri, 20 Juni 2011
    @Autowired
    public void setAvgMouldingDao(AvgMouldingDao avgMouldingDao) {
        this.avgMouldingDao = avgMouldingDao;
    }

    @Autowired
    public void setAverageMouldingDao(AverageMouldingDao averageMouldingDao){
        this.averageMouldingDao = averageMouldingDao;
    }
    

    @Autowired
    private void setAvgOdcDao(AvgOdcDao avgOdcDao){
      this.avgOdcDao = avgOdcDao;
    }
    
    @Autowired
    private void setOdcDao(OdcDao odcDao){
      this.odcDao = odcDao;
    }

    @Autowired
    private void setTStockDao(TStockDao stockDao){
      this.stockDao = stockDao;
    }
    
    @Autowired
    public void setIncomingUsageDao(TIncomingUsageDao tIncomingUsageDao) {
        this.tIncomingUsageDao = tIncomingUsageDao;
    }
  
    @Autowired
    public void setNotereportDao(NotereportDao notereportDao) {
        this.notereportDao = notereportDao;
    }
    @Autowired
    public void setExchangeRateDao(ExchangeRateDao exchangeRateDao) {
        this.exchangeRateDao = exchangeRateDao;
    }

    @Autowired
    public void setGraphDisaDao(GraphDisaDao graphDisaDao) {
        this.graphDisaDao = graphDisaDao;
    }

    @Autowired
    public void setGraphCsHollowDao(GraphCsHollowDao graphCsHollowDao) {
        this.graphCsHollowDao = graphCsHollowDao;
    }

    @Autowired
    public void setAvgStopTimeDao(AvgStopTimeDao avgStopTimeDao) {
        this.avgStopTimeDao = avgStopTimeDao;
    }

    @Autowired
    public void setGraph2mlDao(Graph2mlDao graph2mlDao) {
        this.graph2mlDao = graph2mlDao;
    }

    @Autowired
    public void setGraphSm60Dao(GraphSm60Dao graphSm60Dao) {
        this.graphSm60Dao = graphSm60Dao;
    }

    @Autowired
    public void setGraphPmsDao(GraphPmsDao graphPmsDao) {
        this.graphPmsDao = graphPmsDao;
    }

    @Autowired
    public void setNewItemDao(NewItemDao newItemDao) {
        this.newItemDao = newItemDao;
    }

    @Autowired
    public void setTdqDao(TdqDao tdqDao) {
        this.tdqDao = tdqDao;
    }

    @Autowired
    public void setRejectionMouldHollowDao(TRejectionMouldHollowDao tRejectionMouldHollowDao) {
        this.tRejectionMouldHollowDao = tRejectionMouldHollowDao;
    }

    @Autowired
    public void setRejectionMouldDisaDao(TRejectionMouldDisaDao tRejectionMouldDisaDao) {
        this.tRejectionMouldDisaDao = tRejectionMouldDisaDao;
    }

    @Autowired
    public void setRejectionMouldSm60Dao(TRejectionMouldSm60Dao tRejectionMouldSm60Dao) {
        this.tRejectionMouldSm60Dao = tRejectionMouldSm60Dao;
    }

    @Autowired
    public void setRejectionMouldPmsDao(TRejectionMouldPmsDao tRejectionMouldPmsDao) {
        this.tRejectionMouldPmsDao = tRejectionMouldPmsDao;
    }

    @Autowired
    public void setRejectionMouldSsmDao(TRejectionMouldSSMDao tRejectionMouldSSMDao) {
        this.tRejectionMouldSSMDao = tRejectionMouldSSMDao;
    }
    
    @Autowired
    public void setRejectionMouldDao(TRejectionMouldDao rejectionMouldDao) {
        this.rejectionMouldDao = rejectionMouldDao;
    }


    @Autowired
    public void setsSDao(StockDao sSDao) {
        this.sSDao = sSDao;
    }

   

    @Autowired
    private void setK3Dao(K3Dao k3Dao){
      this.k3Dao = k3Dao;
    }

    @Autowired
    private void setPfDao(PfrekapDao pfrekapDao){
      this.pfrekapDao = pfrekapDao;
    }

    @Autowired
    private void setListrikDao(ListrikDao listrikDao){
      this.listrikDao = listrikDao;
    }

    @Autowired
    private void setPfDao(PfDao pfDao){
      this.pfDao = pfDao;
    }
    @Autowired
    private void setcompDao(CompDao compDao){
      this.compDao = compDao;
    }
    @Autowired
    private void setPreInspectionDao(PreInspectionDao preInspectionDao){
      this.preInspectionDao = preInspectionDao;
    }
    
    @Autowired
    private void setExchangeCurrencyDao(ExchangeCurrencyImpl exchangeCurrencyDao){
      this.exchangeCurrencyDao = exchangeCurrencyDao;
    }
    @Autowired
    private void setRejectGalvaDao(RejectGalvaImpl rejectGalvaDao){
      this.rejectGalvaDao = rejectGalvaDao;
    }
    
    @Autowired
    private void setRejectMachiningDao(RejectMachiningDao rejectMachiningDao){
      this.rejectMachiningDao = rejectMachiningDao;
    }

    @Autowired
    private void setRejectCastingDao(RejectCastingDao rejectCastingDao){
      this.rejectCastingDao = rejectCastingDao;
    }
    

    @RequestMapping("/index.htm")
    public void indexPage(){
        
    }
   
    @RequestMapping("/view-rate-data.htm")
    public void viewExchangeRate(ModelMap map,HttpServletRequest req){
        //String start = req.getParameter("start");
        //String end = req.getParameter("end");
        String id = req.getParameter("id");


        int maxValue = 15;
        if(req.getParameter("max") != null){
            maxValue = Integer.valueOf(req.getParameter("max")).intValue();
        }

        String notequery = "from Notereport where type='exchange_rate_table'";

        String query= "from ExchangeRate order by id desc";
        if(id != null ){
            ExchangeRate rg = new ExchangeRate();
            rg.setId(Long.parseLong(id));
            this.exchangeRateDao.delete(rg);

            map.addAttribute("msg","Data has been deleted");

        }


        List notedata = this.notereportDao.getAll(notequery);
        
        
        Notereport nr = (Notereport) notedata.get(0);

        this.exchangeRateDao.hibernateTemplate.setMaxResults(maxValue);
        List data = this.exchangeRateDao.custom(query);

       
        map.addAttribute("idnote", nr.getId());
        map.addAttribute("note",nr.getNotes().replaceAll("\n","<br/>"));
        map.addAttribute("data", data);
        map.addAttribute("max",maxValue);
    }

    @RequestMapping("/view-rate-graph.htm")
    public void viewExchangeRateGraph(ModelMap map,HttpServletRequest req){
        //String start = req.getParameter("start");
        //String end = req.getParameter("end");
        int maxValue = 15;
        if(req.getParameter("max") != null){
            maxValue = Integer.valueOf(req.getParameter("max")).intValue();
        }
        

        String notequery = "from Notereport where type='exchange_rate_table'";

        String query= "from ExchangeRate order by id desc";

        
        List notedata = this.notereportDao.custom(notequery);
        
        

        Notereport nr = (Notereport)notedata.get(0);
        
        this.exchangeRateDao.hibernateTemplate.setMaxResults(maxValue);
        List data = this.exchangeRateDao.custom(query);


        
        map.addAttribute("note",nr.getNotes().replaceAll("\n","<br/>"));
        map.addAttribute("data", data);
        map.addAttribute("max",maxValue);
    }

    @RequestMapping("/currentexchange.htm")
    public void currentExchange(HttpServletRequest req,ModelMap map){
        this.startDate = req.getParameter("start");
        this.endDate = req.getParameter("end");

        map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        
    }
    @RequestMapping("/rpusd.htm")
    public void rpUsd(HttpServletRequest req,ModelMap map){
        
        this.startDate = req.getParameter("start");
        this.endDate = req.getParameter("end");
        
        map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        
    }

    @RequestMapping("/rpjpy.htm")
    public void rpyen(HttpServletRequest req,ModelMap map){
        this.startDate = req.getParameter("start");
        this.endDate = req.getParameter("end");
        map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
    }

    @RequestMapping("/usdjpy.htm")
    public void usdyen(HttpServletRequest req,ModelMap map){
        this.startDate = req.getParameter("start");
        this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
    }
    @RequestMapping("/showdatacurrency.htm")
    public void showDataCurrency(ModelMap map,HttpServletRequest req){

        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from ExchangeCurrency where date between'"+start+"' and '"+end+"' order by date desc";
        if(id != null ){
            ExchangeCurrency ec = new ExchangeCurrency();
            ec.setId(Long.parseLong(id));
            //ec.setDate(null);
            this.exchangeCurrencyDao.delete(ec);
            map.addAttribute("msg","Data has been deleted");
            
        }
        List data = this.exchangeCurrencyDao.getAll(query);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-galva-data.htm")
    public void viewGalvaData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from RejectGalva where date between '"+start+"' and '"+end+"' order by date desc";
        if(id != null ){
            RejectGalva rg = new RejectGalva();
            rg.setId(Long.parseLong(id));
            this.rejectGalvaDao.delete(rg);
       
            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.rejectGalvaDao.getAll(query);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-preinsp-data.htm")
    public void viewPreInsData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from Preinspection where date between '"+start+"' and '"+end+"' order by date desc";
        if(id != null ){
            Preinspection pi = new Preinspection();
            pi.setId(Long.parseLong(id));
            this.preInspectionDao.delete(pi);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.preInspectionDao.getAll(query);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-preinsp-table.htm")
    public void viewPreInsTable(ModelMap map,HttpServletRequest req){
        String start;
        String end;
        if(req.getParameter("start").isEmpty() || req.getParameter("end").isEmpty()){
            start = MainController.startDate;
            end = MainController.endDate;
        }else{
            start=req.getParameter("start");
            end=req.getParameter("end");
        }
        

        String id = req.getParameter("id");

        String query= "from Preinspection where date between '"+start+"' and '"+end+"' order by date asc";
        
        List data = this.preInspectionDao.getAll(query);
        map.addAttribute("data", data);
    }
   
    @RequestMapping("/view-casting-data.htm")
    public void viewCastingData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from RejectCasting where date between '"+start+"' and '"+end+"' order by date desc limit 0,31";
        if(id != null ){
            RejectCasting rc = new RejectCasting();
            rc.setId(Long.parseLong(id));
            this.rejectCastingDao.delete(rc);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.rejectCastingDao.getAll(query);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-machining-data.htm")
    public void viewMachiningData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from RejectMachining where date between '"+start+"' and '"+end+"' order by date desc";
        if(id != null ){
            RejectMachining rm = new RejectMachining();
            rm.setId(Long.parseLong(id));
            this.rejectMachiningDao.delete(rm);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.rejectMachiningDao.getAll(query);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-k3-data.htm")
    public void viewK3Data(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        if(start == null){
            start = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-01";

        }

        if(end == null ){
            if((CommonUtil.getCurrentMonth()%2)==0){
                if(CommonUtil.getCurrentMonth()==2){
                    end = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-28";
                }else{
                    end = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-30";
                }

            }else{
                end = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-31";
            }


        }

        String query= "from K3 where date between '"+start+"' and '"+end+"' order by date desc";
        if(id != null ){
            K3 k3 = new K3();
            k3.setId(Long.parseLong(id));
            this.k3Dao.delete(k3);
            System.out.println(id);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.k3Dao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }
    
    @RequestMapping("/view-galva-graph.htm")
    public void viewGalvaGraph(ModelMap map,HttpServletRequest req){
      
      
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

       String query= "from RejectGalva where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
       List data = this.rejectGalvaDao.getAll(query);
       map.addAttribute("data", data);
    }

        
     @RequestMapping("/view-casting-graph.htm")
    public void viewCastingGraph(ModelMap map,HttpServletRequest req){


       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
       String query= "from RejectCasting where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";

       List data = this.rejectCastingDao.getAll(query);
       map.addAttribute("data", data);
    }

    @RequestMapping("/view-machining-graph.htm")
    public void viewMachiningGraph(ModelMap map,HttpServletRequest req){


       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

       String query= "from RejectMachining where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
        
        List data = this.rejectMachiningDao.getAll(query);
        map.addAttribute("data", data);

    }

    @RequestMapping("/view-preinsp-graph.htm")
    public void viewPreInspGraph(ModelMap map,HttpServletRequest req){


       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

       String query= "from Preinspection where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";

       List data = this.preInspectionDao.getAll(query);
       map.addAttribute("data", data);


    }

    @RequestMapping("/view-comp-graph.htm")
    public void vieCompGraph(ModelMap map,HttpServletRequest req){


       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

       List data = this.compDao.getAll("from Comp where date between '"+startDate+"' and '"+endDate+"' order by date asc");
       map.addAttribute("data", data);


    }

     @RequestMapping("/view-pf-graph.htm")
    public void viewPfGraph(ModelMap map,HttpServletRequest req){


       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


        List data = this.pfDao.getAll("from Pf where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc");
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-listrik-graph.htm")
    public void viewListrikGraph(ModelMap map,HttpServletRequest req){


       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

       List data = this.listrikDao.getAllByDate(MainController.startDate,MainController.endDate);
       map.addAttribute("data", data);



    }

    @RequestMapping("/view-pfrekap-graph.htm")
    public void viewpfRekapGraph(ModelMap map,HttpServletRequest req){


       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

     



    }

    @RequestMapping("/view-comp-data.htm")
    public void compData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");
        if(id != null ){
            Comp c = new Comp();
            c.setId(Long.parseLong(id));
            this.compDao.delete(c);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.compDao.getAll("from Comp where date between '"+start+"' and '"+end+"' order by date asc");
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-pf-data.htm")
    public void pfData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");
        if(id != null ){
            Pf c = new Pf();
            c.setId(Long.parseLong(id));
            this.pfDao.delete(c);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.pfDao.getAll("from Pf where date between '"+start+"' and '"+end+"' order by date desc");
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-listrik-data.htm")
    public void ListrikData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");
        if(id != null ){
            Listrik c = new Listrik();
            c.setId(Long.parseLong(id));
            this.listrikDao.delete(c);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.listrikDao.getAll("from Listrik where bulan between '"+start+"' and '"+end+"' order by bulan desc");
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-pfrekap-data.htm")
    public void PfRekapData(ModelMap map,HttpServletRequest req){
        String id = req.getParameter("id");
        if(id != null ){
            Pfrekap c = new Pfrekap();
            c.setId(Long.parseLong(id));
            this.pfrekapDao.delete(c);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.pfrekapDao.getAll("from Pfrekap order by id asc limit 0,31");
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-stock-data.htm")
    public void viewStockData(ModelMap map, HttpServletRequest request) {
        String id = request.getParameter("id");


        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        if(startDate == null){
            startDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-01";
            
        }

        if(endDate == null ){
            if((CommonUtil.getCurrentMonth()%2)==0){
                if(CommonUtil.getCurrentMonth()==2){
                    endDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-28";
                }else{
                    endDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-30";
                }
                
            }else{
                endDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-31";
            }


        }

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);
        
        if (id != null) {
            TIncomingUsage tIncomingUsage = new TIncomingUsage();
            tIncomingUsage.setId(Integer.parseInt(id));
            this.tIncomingUsageDao.delete(tIncomingUsage);

            map.addAttribute("msg", "Data has been deleted");
        }
        //this.tIncomingUsageDao.hibernateTemplate.setMaxResults(30);
        
        List data = this.tIncomingUsageDao.getAllByDate(startDate, endDate);
        
        map.addAttribute("data", data);
    }
    @RequestMapping("/view-ss-bargraph.htm")
    public void viewSsBarGraph(ModelMap map, HttpServletRequest request) {
       startDate = request.getParameter("start");
       endDate = request.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
       if(startDate == null){
            startDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-01";

        }

        if(endDate == null ){
            if((CommonUtil.getCurrentMonth()%2)==0){
                if(CommonUtil.getCurrentMonth()==2){
                    endDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-28";
                }else{
                    endDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-30";
                }

            }else{
                endDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-31";
            }


        }
       
       List data1 = this.tIncomingUsageDao.getAllByDate(startDate, endDate);
       map.addAttribute("data", data1);
    }
    
    @RequestMapping("/view-ss-linegraph.htm")
    public void viewStockLineGraph(ModelMap map, HttpServletRequest request) {
       startDate = request.getParameter("start");
       endDate = request.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

       

       if(startDate == null){
            startDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-01";

        }

        if(endDate == null ){
            if((CommonUtil.getCurrentMonth()%2)==0){
                if(CommonUtil.getCurrentMonth()==2){
                    endDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-28";
                }else{
                    endDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-30";
                }

            }else{
                endDate = CommonUtil.getCurrentYear()+"-"+CommonUtil.getCurrentMonth()+"-31";
            }


        }
       
            List data1 = this.tIncomingUsageDao.getAllByDate(startDate, endDate);
            map.addAttribute("data", data1);

            //List data2;
            /*
            String[] tempIdStock = startDate.split("-");
            String idStock = tempIdStock[1]+tempIdStock[0];
            data2 = this.stockDao.getById(idStock);
            TStock tStock = (TStock) data2.get(0);
            */
            if(data1.size() > 0){

            TIncomingUsage tUsage = (TIncomingUsage) data1.get(0);
            map.addAttribute("startPlanStock", tUsage.getIdStock().getPlanStock());
            map.addAttribute("startActualStock", tUsage.getIdStock().getStockActual());
            }
       

       
      

        
    }

    @RequestMapping("/view-tstock-data.htm")
    public void viewTStockData(ModelMap map, HttpServletRequest req) {
       String id = req.getParameter("id");
       if (id != null) {
            TStock tStock = new TStock();
            tStock.setIdStock(id);
            this.stockDao.delete(tStock);

            map.addAttribute("msg", "Data has been deleted");
        }
       
       List data = this.stockDao.getAll("from TStock order by idStock desc");

       map.addAttribute("data",data);
    }

   
    

    @RequestMapping("/view-mould-data.htm")
    public void viewMouldData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            TRejectionMould data = new TRejectionMould();
            data.setId(Long.parseLong(id));
            this.rejectionMouldDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.rejectionMouldDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-graph.htm")
    public void viewMouldGraph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);

        List data = this.rejectionMouldDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-ssm-data.htm")
    public void viewMouldSsmData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            TRejectionMouldSsm data = new TRejectionMouldSsm();
            data.setId(Long.parseLong(id));
            this.tRejectionMouldSSMDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.tRejectionMouldSSMDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-ssm-graph.htm")
    public void viewMouldSsmGraph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);
        List data = this.tRejectionMouldSSMDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-pms-data.htm")
    public void viewMouldPmsData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            TRejectionMouldPms data = new TRejectionMouldPms();
            data.setId(Long.parseLong(id));
            this.tRejectionMouldPmsDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.tRejectionMouldPmsDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-pms-graph.htm")
    public void viewMouldPmsGraph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);
        List data = this.tRejectionMouldPmsDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-sm60-data.htm")
    public void viewMouldSm60Data(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            TRejectionMouldSm60 data = new TRejectionMouldSm60();
            data.setId(Long.parseLong(id));
            this.tRejectionMouldSm60Dao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.tRejectionMouldSm60Dao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-sm60-graph.htm")
    public void viewMouldSm60Graph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);
        List data = this.tRejectionMouldSm60Dao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-disa-data.htm")
    public void viewMouldDisaData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            TRejectionMouldDisa data = new TRejectionMouldDisa();
            data.setId(Long.parseLong(id));
            this.tRejectionMouldDisaDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.tRejectionMouldDisaDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-disa-graph.htm")
    public void viewMouldDisaGraph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);
        List data = this.tRejectionMouldDisaDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-hollow-data.htm")
    public void viewMouldHollowData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            TRejectionMouldHollow data = new TRejectionMouldHollow();
            data.setId(Long.parseLong(id));
            this.tRejectionMouldHollowDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.tRejectionMouldHollowDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-mould-hollow-graph.htm")
    public void viewMouldHollowGraph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);
        List data = this.tRejectionMouldHollowDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-newitem-data.htm")
    public void viewNewItemData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
       if(req.getParameter("year") == null){
           year = Integer.valueOf(CommonUtil.getCurrentYear()).toString() ;
        }else{
           year = req.getParameter("year");
        }
       

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            NewItem data = new NewItem();
            data.setId(Long.parseLong(id));
            this.newItemDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.newItemDao.getAllByYear(year);
        map.addAttribute("data", data);
        map.addAttribute("year", year);
        map.addAttribute("minYear", CommonUtil.getCurrentYear()-5);
        map.addAttribute("maxYear", CommonUtil.getCurrentYear()+5);
    }
    
    @RequestMapping("/view-newitem-table.htm")
    public void viewNewItemTable(ModelMap map, HttpServletRequest request) {
         if(request.getParameter("year") == null){
           year = Integer.valueOf(CommonUtil.getCurrentYear()).toString() ;
        }else{
           year = request.getParameter("year");
        }

        List data1 = this.newItemDao.getAllByMonth2("1", year);
        List data2 = this.newItemDao.getAllByMonth2("2", year);
        List data3 = this.newItemDao.getAllByMonth2("3", year);
        List data4 = this.newItemDao.getAllByMonth2("4", year);
        List data5 = this.newItemDao.getAllByMonth2("5", year);
        List data6 = this.newItemDao.getAllByMonth2("6", year);
        List data7 = this.newItemDao.getAllByMonth2("7", year);
        List data8 = this.newItemDao.getAllByMonth2("8", year);
        List data9 = this.newItemDao.getAllByMonth2("9", year);
        List data10 = this.newItemDao.getAllByMonth2("10", year);
        List data11 = this.newItemDao.getAllByMonth2("11", year);
        List data12 = this.newItemDao.getAllByMonth2("12", year);



        map.addAttribute("size1", data1.size());
        map.addAttribute("size2", data2.size());
        map.addAttribute("size3", data3.size());
        map.addAttribute("size4", data4.size());
        map.addAttribute("size5", data5.size());
        map.addAttribute("size6", data6.size());
        map.addAttribute("size7", data7.size());
        map.addAttribute("size8", data8.size());
        map.addAttribute("size9", data9.size());
        map.addAttribute("size10", data10.size());
        map.addAttribute("size11", data11.size());
        map.addAttribute("size12", data12.size());

        map.addAttribute("data1", data1);
        map.addAttribute("data2", data2);
        map.addAttribute("data3", data3);
        map.addAttribute("data4", data4);
        map.addAttribute("data5", data5);
        map.addAttribute("data6", data6);
        map.addAttribute("data7", data7);
        map.addAttribute("data8", data8);
        map.addAttribute("data9", data9);
        map.addAttribute("data10", data10);
        map.addAttribute("data11", data11);
        map.addAttribute("data12", data12);

        map.addAttribute("year", year);
        map.addAttribute("minYear", CommonUtil.getCurrentYear()-5);
        map.addAttribute("maxYear", CommonUtil.getCurrentYear()+5);

    }
    @RequestMapping("/view-newitem-graph.htm")
    public void viewNewItemGraph(ModelMap map, HttpServletRequest request) {

        
        if(request.getParameter("year") == null){
           year = Integer.valueOf(CommonUtil.getCurrentYear()).toString() ;
        }else{
           year = request.getParameter("year");
        }

        
        map.addAttribute("year", year);
        map.addAttribute("minYear", CommonUtil.getCurrentYear()-5);
        map.addAttribute("maxYear", CommonUtil.getCurrentYear()+5);
    }
    
    @RequestMapping("/view-tdq-data.htm")
    public void viewTdqData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
       if(req.getParameter("year") == null){
           year = Integer.valueOf(CommonUtil.getCurrentYear()).toString() ;
        }else{
           year = req.getParameter("year");
        }


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            Tdq data = new Tdq();
            data.setId(Long.parseLong(id));
            this.tdqDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.tdqDao.getAllByYear(year);
        map.addAttribute("data", data);
        map.addAttribute("year", year);
        map.addAttribute("minYear", CommonUtil.getCurrentYear()-5);
        map.addAttribute("maxYear", CommonUtil.getCurrentYear()+5);
    }
    
    @RequestMapping("/view-tdq-table.htm")
    public void viewTdqTable(ModelMap map, HttpServletRequest request) {
         if(request.getParameter("year") == null){
           year = Integer.valueOf(CommonUtil.getCurrentYear()).toString() ;
        }else{
           year = request.getParameter("year");
        }

        List data1 = this.tdqDao.getAllByMonth2("1", year);
        List data2 = this.tdqDao.getAllByMonth2("2", year);
        List data3 = this.tdqDao.getAllByMonth2("3", year);
        List data4 = this.tdqDao.getAllByMonth2("4", year);
        List data5 = this.tdqDao.getAllByMonth2("5", year);
        List data6 = this.tdqDao.getAllByMonth2("6", year);
        List data7 = this.tdqDao.getAllByMonth2("7", year);
        List data8 = this.tdqDao.getAllByMonth2("8", year);
        List data9 = this.tdqDao.getAllByMonth2("9", year);
        List data10 = this.tdqDao.getAllByMonth2("10", year);
        List data11 = this.tdqDao.getAllByMonth2("11", year);
        List data12 = this.tdqDao.getAllByMonth2("12", year);



        map.addAttribute("size1", data1.size());
        map.addAttribute("size2", data2.size());
        map.addAttribute("size3", data3.size());
        map.addAttribute("size4", data4.size());
        map.addAttribute("size5", data5.size());
        map.addAttribute("size6", data6.size());
        map.addAttribute("size7", data7.size());
        map.addAttribute("size8", data8.size());
        map.addAttribute("size9", data9.size());
        map.addAttribute("size10", data10.size());
        map.addAttribute("size11", data11.size());
        map.addAttribute("size12", data12.size());

        map.addAttribute("data1", data1);
        map.addAttribute("data2", data2);
        map.addAttribute("data3", data3);
        map.addAttribute("data4", data4);
        map.addAttribute("data5", data5);
        map.addAttribute("data6", data6);
        map.addAttribute("data7", data7);
        map.addAttribute("data8", data8);
        map.addAttribute("data9", data9);
        map.addAttribute("data10", data10);
        map.addAttribute("data11", data11);
        map.addAttribute("data12", data12);

        map.addAttribute("year", year);
        map.addAttribute("minYear", CommonUtil.getCurrentYear()-5);
        map.addAttribute("maxYear", CommonUtil.getCurrentYear()+5);

    }

    @RequestMapping("/view-tdq-graph.htm")
    public void viewTdqGraph(ModelMap map, HttpServletRequest request) {


        if(request.getParameter("year") == null){
           year = Integer.valueOf(CommonUtil.getCurrentYear()).toString() ;
        }else{
           year = request.getParameter("year");
        }


        map.addAttribute("year", year);
        map.addAttribute("minYear", CommonUtil.getCurrentYear()-5);
        map.addAttribute("maxYear", CommonUtil.getCurrentYear()+5);
    }

    
	
	//Johan
	 /*Start Here*/

    @RequestMapping("/view-pms-data.htm")
     public void viewGraphPmsData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
        this.endDate = req.getParameter("end");


        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);
        if (id != null) {
            GraphPms data = new GraphPms();
            data.setId(Long.parseLong(id));
            this.graphPmsDao.delete(data);

            
            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.graphPmsDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-pms-graph.htm")
    public void viewGraphPmsGraph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");
        //Start Update Avg
        System.out.println("mulai");
            List curAvg = graphPmsDao.custom("select avg(batasmax) from GraphPms"+
                         " where batasmax <> 0 and YEAR(date) = '"+Integer.toString(CommonUtil.getCurrentYear())+"'");
            List curAvg1 = graphPmsDao.custom("select avg(frekwensi) from GraphPms"+
                             " where frekwensi <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg2 = graphPmsDao.custom("select avg(actualmould)+avg(actualsand) from GraphPms"+
                             " where actualmould <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg3 = graphPmsDao.custom("select avg(actualmould) from GraphPms"+
                             " where actualmould <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg4 = graphPmsDao.custom("select avg(actualsand) from GraphPms"+
                             " where actualsand <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");

            String strcurAvg = curAvg.get(0).toString();
            String strcurAvg1 = curAvg1.get(0).toString();
            String strcurAvg2 = curAvg2.get(0).toString();
            String strcurAvg3 = curAvg3.get(0).toString();
            String strcurAvg4 = curAvg4.get(0).toString();

            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg),"batas max PMS");
            System.out.println("Rata2 batasMAX th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg);

            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg1),"frekwensi PMS");
            System.out.println("Rata2 Frekwensi th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg1);

            saveAvg(CommonUtil.getCurrentYear(), Double.parseDouble(strcurAvg2), "actual PMS");
            System.out.println("Rata2 ActualPMS th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg2);

            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg3),"actual mould PMS");
            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg4),"actual sand tr PMS");
            System.out.println("done");
            //End Update Avg

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);

        String query= "from GraphPms where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
        String query_actual_pms = "from AvgStopTime where jenis='actual PMS' order by tahun asc ";
        String query_mould = "from AvgStopTime where jenis='actual mould PMS' order by tahun asc ";
        String query_sandtr = "from AvgStopTime where jenis='actual sand tr PMS' order by tahun asc ";
        String query_batas_max_pms = "from AvgStopTime where jenis='batas max PMS' order by tahun asc";
        String query_frekwensi_pms = "from AvgStopTime where jenis='frekwensi PMS' order by tahun asc";
        String query_total_pms = "select (actualmould + actualsand) from GraphPms where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";


        List data = this.graphPmsDao.getAll(query);
        map.addAttribute("data", data);

        List avgMould = this.avgStopTimeDao.getAll(query_mould);
        map.addAttribute("avgmould",avgMould);

        List avgSand = this.avgStopTimeDao.getAll(query_sandtr);
        map.addAttribute("avgsand",avgSand);

        List rata = this.avgStopTimeDao.getAll(query_actual_pms);
        map.addAttribute("rata", rata);

        List rata2 = this.avgStopTimeDao.getAll(query_batas_max_pms);
        map.addAttribute("rata2", rata2);

        List rata3 = this.avgStopTimeDao.getAll(query_frekwensi_pms);
        map.addAttribute("rata3", rata3);

        List total = this.graphPmsDao.getAll(query_total_pms);
        map.addAttribute("total",total);

    }

    @RequestMapping("/view-sm60-data.htm")
     public void viewGraphSm60Data(ModelMap map, HttpServletRequest req) {
       String id = req.getParameter("id");
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            GraphSm60 data = new GraphSm60();
            data.setId(Long.parseLong(id));
            this.graphSm60Dao.delete(data);

            

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.graphSm60Dao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-sm60-graph.htm")
    public void viewGraphSm60Graph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);

        System.out.println("mulai");
            List curAvg = graphSm60Dao.custom("select avg(batasmax) from GraphSm60"+
                         " where batasmax <> 0 and YEAR(date) = '"+Integer.toString(CommonUtil.getCurrentYear())+"'");
            List curAvg1 = graphSm60Dao.custom("select avg(frekwensi) from GraphSm60"+
                             " where frekwensi <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg2 = graphSm60Dao.custom("select avg(actualmould)+avg(actualsand) from GraphSm60"+
                             " where actualmould <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg3 = graphSm60Dao.custom("select avg(actualmould) from GraphSm60"+
                             " where actualmould <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg4 = graphSm60Dao.custom("select avg(actualsand) from GraphSm60"+
                             " where actualsand <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");

            String strcurAvg = curAvg.get(0).toString();
            String strcurAvg1 = curAvg1.get(0).toString();
            String strcurAvg2 = curAvg2.get(0).toString();
            String strcurAvg3 = curAvg3.get(0).toString();
            String strcurAvg4 = curAvg4.get(0).toString();

            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg),"batas max SM60");
            System.out.println("Rata2 batasMAX SM60 th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg);

            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg1),"frekwensi SM60");
            System.out.println("Rata2 Frekwensi SM60 th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg1);

            saveAvg(CommonUtil.getCurrentYear(), Double.parseDouble(strcurAvg2), "actual SM60");
            System.out.println("Rata2 ActualSM60 th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg2);

            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg3),"actual mould SM60");
            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg4),"actual sand tr SM60");
            System.out.println("done");

        String query= "from GraphSm60 where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
        String query_mould = "from AvgStopTime where jenis='actual mould SM60' order by tahun asc ";
        String query_sandtr = "from AvgStopTime where jenis='actual sand tr SM60' order by tahun asc ";
        String query_actual_sm60 = "from AvgStopTime where jenis='actual SM60' order by tahun asc ";
        String query_batas_max_sm60 = "from AvgStopTime where jenis='batas max SM60' order by tahun asc";
        String query_frekwensi_sm60 = "from AvgStopTime where jenis='frekwensi SM60' order by tahun asc";
        String query_total_sm60 = "select (actualmould + actualsand) from GraphSm60 where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";

        List data = this.graphSm60Dao.custom(query);
        map.addAttribute("data", data);

        List avgMould = this.graphSm60Dao.getAll(query_mould);
        map.addAttribute("avgmould",avgMould);

        List avgSand = this.graphSm60Dao.getAll(query_sandtr);
        map.addAttribute("avgsand",avgSand);

        List rata = this.graphSm60Dao.custom(query_actual_sm60);
        map.addAttribute("rata", rata);

        List rata2 = this.graphSm60Dao.custom(query_batas_max_sm60);
        map.addAttribute("rata2", rata2);

        List rata3 = this.graphSm60Dao.custom(query_frekwensi_sm60);
        map.addAttribute("rata3", rata3);

        List total = this.graphSm60Dao.custom(query_total_sm60);
        map.addAttribute("total",total);
    }

    @RequestMapping("/view-2ml-data.htm")
     public void viewGraph2mlData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            Graph2ml data = new Graph2ml();
            data.setId(Long.parseLong(id));
            this.graph2mlDao.delete(data);

            

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.graph2mlDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-2ml-graph.htm")
    public void viewGraph2mlGraph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);

        //Start Avg
        System.out.println("mulai");
            List curAvg = graph2mlDao.custom("select avg(batasmax) from Graph2ml"+
                         " where batasmax <> 0 and YEAR(date) = '"+Integer.toString(CommonUtil.getCurrentYear())+"'");
            List curAvg1 = graph2mlDao.custom("select avg(frekwensi) from Graph2ml"+
                             " where frekwensi <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg2 = graph2mlDao.custom("select avg(actualmould)+avg(actualsand) from Graph2ml"+
                             " where actualmould <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg3 = graph2mlDao.custom("select avg(actualmould) from Graph2ml"+
                             " where actualmould <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg4 = graph2mlDao.custom("select avg(actualsand) from Graph2ml"+
                             " where actualsand <> 0 and YEAR(date) = '"+
                             Integer.toString(CommonUtil.getCurrentYear()) +"'");

            String strcurAvg = curAvg.get(0).toString();
            String strcurAvg1 = curAvg1.get(0).toString();
            String strcurAvg2 = curAvg2.get(0).toString();
            String strcurAvg3 = curAvg3.get(0).toString();
            String strcurAvg4 = curAvg4.get(0).toString();

            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg),"batas max 2ML");
            System.out.println("Rata2 batasMAX 2ML th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg);

            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg1),"frekwensi 2ML");
            System.out.println("Rata2 Frekwensi 2ML th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg1);

            saveAvg(CommonUtil.getCurrentYear(), Double.parseDouble(strcurAvg2), "actual 2ML");
            System.out.println("Rata2 Actual 2ML th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg2);

            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg3),"actual mould 2ML");
            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg4),"actual sand tr 2ML");
            System.out.println("done");
            //End Avg

        String query= "from Graph2ml where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
        String query_mould = "from AvgStopTime where jenis='actual mould 2ML' order by tahun asc ";
        String query_sandtr = "from AvgStopTime where jenis='actual sand tr 2ML' order by tahun asc ";
        String query_actual_2ml = "from AvgStopTime where jenis='actual 2ML' order by tahun asc ";
        String query_batas_max_2ml = "from AvgStopTime where jenis='batas max 2ML' order by tahun asc";
        String query_frekwensi_2ml = "from AvgStopTime where jenis='frekwensi 2ML' order by tahun asc";
        String query_total_2ml = "select (actualmould + actualsand) from Graph2ml where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";

        List data = this.graph2mlDao.getAll(query);
        map.addAttribute("data", data);

        List avgMould = this.graph2mlDao.getAll(query_mould);
        map.addAttribute("avgmould",avgMould);

        List avgSand = this.graph2mlDao.getAll(query_sandtr);
        map.addAttribute("avgsand",avgSand);

        List rata = this.graph2mlDao.getAll(query_actual_2ml);
        map.addAttribute("rata", rata);

        List rata2 = this.graph2mlDao.getAll(query_batas_max_2ml);
        map.addAttribute("rata2", rata2);

        List rata3 = this.graph2mlDao.getAll(query_frekwensi_2ml);
        map.addAttribute("rata3", rata3);

        List total = this.graph2mlDao.getAll(query_total_2ml);
        map.addAttribute("total",total);
    }

    /* Data2 Average Stop Time Moulding*/
    @RequestMapping("/view-avg-pms-data.htm")
     public void viewAvgPmsData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            AvgStopTime data = new AvgStopTime();
            data.setId(Long.parseLong(id));
            this.avgStopTimeDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.avgStopTimeDao.getAll("from AvgStopTime where jenis like '%PMS' " +
                "AND tahun between '"+startDate+"' AND '"+endDate+"' " +
                "order by tahun asc");
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-avg-sm60-data.htm")
     public void viewAvgSm60Data(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            AvgStopTime data = new AvgStopTime();
            data.setId(Long.parseLong(id));
            this.avgStopTimeDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.avgStopTimeDao.getAll("from AvgStopTime where jenis like '%SM60' " +
                "AND tahun between '"+startDate+"' AND '"+endDate+"' " +
                "order by tahun asc");
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-avg-2ml-data.htm")
     public void viewAvg2mlData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            AvgStopTime data = new AvgStopTime();
            data.setId(Long.parseLong(id));
            this.avgStopTimeDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.avgStopTimeDao.getAll("from AvgStopTime where jenis like '%2ML' " +
                "AND tahun between '"+startDate+"' AND '"+endDate+"' " +
                "order by tahun asc");
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-avg-cs-hollow-data.htm")
     public void viewAvgCsHollowData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            AvgStopTime data = new AvgStopTime();
            data.setId(Long.parseLong(id));
            this.avgStopTimeDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.avgStopTimeDao.getAll("from AvgStopTime where jenis like '%HLW' " +
                "AND tahun between '"+startDate+"' AND '"+endDate+"' " +
                "order by tahun asc");
        map.addAttribute("data", data);
    }

@RequestMapping("/view-avg-disa-data.htm")
     public void viewAvgDisaData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            AvgStopTime data = new AvgStopTime();
            data.setId(Long.parseLong(id));
            this.avgStopTimeDao.delete(data);

            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.avgStopTimeDao.getAll("from AvgStopTime where jenis like '%DISA' " +
                "AND tahun between '"+startDate+"' AND '"+endDate+"' " +
                "order by tahun asc");
        map.addAttribute("data", data);
    }

/*===============================================================================================*/

    @RequestMapping("/view-cs-hollow-data.htm")
     public void viewGraphCsHollowData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
        this.endDate = req.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);
        if (id != null) {
            GraphCsHollow data = new GraphCsHollow();
            data.setId(Long.parseLong(id));
            this.graphCsHollowDao.delete(data);



            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.graphCsHollowDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-cs-hollow-graph.htm")
    public void viewGraphCsHollowGraph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);

        //Start set avg
                    List curAvg1 = graphCsHollowDao.custom("select avg(actualcshlw) from GraphCsHollow"+
                         " where  YEAR(date) = '"+
                         Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg2 = graphCsHollowDao.custom("select avg(batasmax) from GraphCsHollow"+
                         " where  YEAR(date) = '"+
                         Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg3 = graphCsHollowDao.custom("select avg(frekwensi) from GraphCsHollow"+
                         " where YEAR(date) = '"+
                         Integer.toString(CommonUtil.getCurrentYear()) +"'");

            String strcurAvg1 = curAvg1.get(0).toString();
            String strcurAvg2 = curAvg2.get(0).toString();
            String strcurAvg3 = curAvg3.get(0).toString();

            saveAvg(CommonUtil.getCurrentYear(), Double.parseDouble(strcurAvg1), "actual CS HLW");
            System.out.println("Rata2 actualCsHlw th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg1);

            saveAvg(CommonUtil.getCurrentYear(), Double.parseDouble(strcurAvg2), "batas max CS HLW");
            System.out.println("Rata2 batasMAX th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg2);


            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg3),"frekwensi CS HLW");
            System.out.println("Rata2 batasMAX th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg2);
        //End set Avg

        String query= "from GraphCsHollow where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
        String query_actual_cs = "from AvgStopTime where jenis='actual CS HLW' order by tahun asc ";
        String query_batas_max_cs = "from AvgStopTime where jenis='batas max CS HLW' order by tahun asc";
        String query_frekwensi_cs = "from AvgStopTime where jenis='frekwensi CS HLW' order by tahun asc";
        List data = this.graphCsHollowDao.getAll(query);
        map.addAttribute("data", data);

        List rata = this.avgStopTimeDao.getAll(query_actual_cs);
        map.addAttribute("rata", rata);

        List rata2 = this.avgStopTimeDao.getAll(query_batas_max_cs);
        map.addAttribute("rata2", rata2);

        List rata3 = this.avgStopTimeDao.getAll(query_frekwensi_cs);
        map.addAttribute("rata3", rata3);
    }

    @RequestMapping("/view-disa-data.htm")
     public void viewGraphDisaData(ModelMap map, HttpServletRequest req) {
        String id = req.getParameter("id");
        this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);
        if (id != null) {
            GraphDisa data = new GraphDisa();
            data.setId(Long.parseLong(id));
            this.graphDisaDao.delete(data);

            
            map.addAttribute("msg", "Data has been deleted");
        }
        List data = this.graphDisaDao.getAllByDate(startDate, endDate);
        map.addAttribute("data", data);
    }

    @RequestMapping("/view-disa-graph.htm")
    public void viewGraphDisaGraph(ModelMap map, HttpServletRequest request) {
        startDate = request.getParameter("start");
        endDate = request.getParameter("end");

        map.addAttribute("start", startDate);
        map.addAttribute("end", endDate);

        //Start Set Avg
        List curAvg1 = graphDisaDao.custom("select avg(actualdisa) from GraphDisa"+
                         " where YEAR(date) = '"+
                         Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg2 = graphDisaDao.custom("select avg(batasmax) from GraphDisa"+
                         " where YEAR(date) = '"+
                         Integer.toString(CommonUtil.getCurrentYear()) +"'");
            List curAvg3 = graphDisaDao.custom("select avg(frekwensi) from GraphDisa"+
                         " where  YEAR(date) = '"+
                         Integer.toString(CommonUtil.getCurrentYear()) +"'");

            String strcurAvg1 = curAvg1.get(0).toString();
            String strcurAvg2 = curAvg2.get(0).toString();
            String strcurAvg3 = curAvg3.get(0).toString();

            saveAvg(CommonUtil.getCurrentYear(), Double.parseDouble(strcurAvg1), "actual DISA");
            System.out.println("Rata2 actual Disa th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg1);

            saveAvg(CommonUtil.getCurrentYear(), Double.parseDouble(strcurAvg2), "batas max DISA");
            System.out.println("Rata2 batasMAX DISA th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg2);


            saveAvg(CommonUtil.getCurrentYear(),Double.parseDouble(strcurAvg3),"frekwensi DISA");
            System.out.println("Rata2 frekwensi DISA th "+
                Integer.toString(CommonUtil.getCurrentYear())+" = "+strcurAvg2);
        //End Set Avg

        String query= "from GraphDisa where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
        String query_actual_disa = "from AvgStopTime where jenis='actual DISA' order by tahun asc ";
        String query_batas_max_disa = "from AvgStopTime where jenis='batas max DISA' order by tahun asc";
        String query_frekwensi_disa = "from AvgStopTime where jenis='frekwensi DISA' order by tahun asc";
        List data = this.graphDisaDao.getAll(query);
        map.addAttribute("data", data);

        List rata = this.avgStopTimeDao.getAll(query_actual_disa);
        map.addAttribute("rata", rata);

        List rata2 = this.avgStopTimeDao.getAll(query_batas_max_disa);
        map.addAttribute("rata2", rata2);

        List rata3 = this.avgStopTimeDao.getAll(query_frekwensi_disa);
        map.addAttribute("rata3", rata3);
    }



    /*
     * FUngsi cek dan update data tahun sekarang
     */
    private void saveAvg(int tahun, double average, String jenis){
        List svAvg = avgStopTimeDao.custom("from AvgStopTime where "+
                "tahun= "+Integer.toString(tahun)+
                " AND jenis='"+jenis+"'");
        AvgStopTime inpAvg;
        if (svAvg.size() > 0) {
            inpAvg = (AvgStopTime)svAvg.get(0);
            
            this.avgStopTimeDao.delete(inpAvg);
        }
        inpAvg = new AvgStopTime();
        inpAvg.setTahun(tahun);
        inpAvg.setJenis(jenis);
        inpAvg.setAverage(average);

        this.avgStopTimeDao.save(inpAvg);
    }

    @RequestMapping("/view-odc-graph.htm")
    public void viewOdcGraph(ModelMap map,HttpServletRequest req){


       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");



       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

       String query= "from Odc where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
       List data = this.odcDao.getAll(query);

       if(this.startDate != null){
        String tempDate[] = this.startDate.split("-");
        int avgStartMonth = Integer.parseInt(tempDate[1]) + 1;
        int avgEndMonth = Integer.parseInt(tempDate[1]) + 4;
        String avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
        String avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        List data2 = this.avgOdcDao.getAllByDate(avgStartDate,avgEndDate );
        
        map.addAttribute("forc", data2);
        
       }
       

       
       
       map.addAttribute("data", data);
       
    }

    @RequestMapping("/view-odc-data.htm")
    public void viewOdcData(ModelMap map,HttpServletRequest req){

       String id = req.getParameter("id");
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");
       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

       

        
        if(id != null ){
            Odc odc = new Odc();
            odc.setId(Long.parseLong(id));
            this.odcDao.delete(odc);

            map.addAttribute("msg","Data has been deleted");

        }

      

       String query= "from Odc where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
       List data = this.odcDao.getAll(query);

       map.addAttribute("data", data);

    }

    @RequestMapping("/view-avgodc-data.htm")
    public void viewAvgOdcData(ModelMap map,HttpServletRequest req){

       String id = req.getParameter("id");
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");
       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);




        if(id != null ){
            Avgodc odc = new Avgodc();
            odc.setId(Long.parseLong(id));
            this.avgOdcDao.delete(odc);

            map.addAttribute("msg","Data has been deleted");

        }



       String query= "from Avgodc where date between '"+this.startDate+"' and '"+this.endDate+"' order by date asc";
       List data = this.odcDao.getAll(query);

       map.addAttribute("data", data);

    }

    //Fikri, 20 Juni 2011
    @RequestMapping("/view-line-moulding.htm")
    public void viewAvgMouldingData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type = 'linemoulding' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-line-moulding-graph.htm")
    public void viewLineMouldingGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");
       String id = req.getParameter("id");



       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);

       if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

       }

       String query= "from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='linemoulding' order by date asc";
       List data = this.avgMouldingDao.getAll(query);
       map.addAttribute("data", data);
    }

    @RequestMapping("/view-average-moulding-data.htm")
    public void viewAverageMouldingData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'linemoulding' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);
    }

    @RequestMapping("/view-average-tapping-data.htm")
    public void viewAverageTappingData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'tapping' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

    @RequestMapping("/view-average-cnc-data.htm")
    public void viewAverageCncData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'cnc' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

    @RequestMapping("/view-tps-average-machining1-data.htm")
    public void viewTPSAverageMachining1Data(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'machining1' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

    @RequestMapping("/view-tps-average-machining2-data.htm")
    public void viewTPSAverageMachining2Data(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'machining2' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

    @RequestMapping("/view-average-machining-comp-data.htm")
    public void viewAverageMcCompData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'mccomp' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }


    @RequestMapping("/view-average-machining-p1-data.htm")
    public void viewAverageMcP1Data(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'mcp1' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

    @RequestMapping("/view-average-mould-foundry-data.htm")
    public void viewAverageMouldFoundryData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'mouldfoundry' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

   @RequestMapping("/view-average-operation-machining-data.htm")
    public void viewAverageOperationMcData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'operation-mc' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

   @RequestMapping("/view-average-mould-pms-data.htm")
    public void viewAverageMouldPMSData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'mouldpms' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

   @RequestMapping("/view-average-mould-sm60-data.htm")
    public void viewAverageMouldSM60Data(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'mouldsm60' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

   @RequestMapping("/view-average-mould-disa-data.htm")
    public void viewAverageMouldDisaData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'moulddisa' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

   @RequestMapping("/view-average-mould-2ml-data.htm")
    public void viewAverageMould2mlData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'mould2ml' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

   @RequestMapping("/view-average-mould-shaft2w-data.htm")
    public void viewAverageMouldShaft2wData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'shaft2w' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

   @RequestMapping("/view-average-mould-shaft4w-data.htm")
    public void viewAverageMouldShaft4wData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AverageMoulding where date between '"+start+"' and '"+end+"' and type = 'shaft4w' order by date desc";
        if(id != null ){
            AverageMoulding am = new AverageMoulding();
            am.setId(Long.parseLong(id));
            this.averageMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.averageMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start",start);
        map.addAttribute("end",end);

    }

   @RequestMapping("/view-average-moulding-graph.htm")
   public void viewAverageMouldingGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");
       

       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='linemoulding' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='linemoulding' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

    @RequestMapping("/view-tapping-data.htm")
    public void viewTappingData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='tapping' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-cnc-data.htm")
    public void viewCNCData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='cnc' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-machining-comp-data.htm")
    public void viewMCCompData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='mccomp' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-machining-p1-data.htm")
    public void viewMCP1Data(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='mcp1' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-kecelakaan-kerja-data.htm")
    public void viewKecelakaanKerjaData(ModelMap map,HttpServletRequest req){
        String id = req.getParameter("id");
        if(req.getParameter("year") != null){
            year = req.getParameter("year");
        }else{
            year = Integer.valueOf(CommonUtil.getCurrentYear()).toString();
        }


        
        
        if(id != null ){
            KecelakaanKerja am = new KecelakaanKerja();
            am.setId(Long.parseLong(id));
            this.kecelakaanKerjaDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        //List data = this.kecelakaanKerjaDao.getAll(query);
        List data = this.kecelakaanKerjaDao.getAllByYear(year);
        map.addAttribute("data", data);
        map.addAttribute("minYear", CommonUtil.getCurrentYear()-3);
        map.addAttribute("maxYear", CommonUtil.getCurrentYear()+3);
        map.addAttribute("currentYear", year);
        
    }

    @RequestMapping("/view-kecelakaan-kerja-graph.htm")
    public void viewKecelakaanKerjaGraph(ModelMap map,HttpServletRequest req){
      
        if(req.getParameter("year") != null){
            year = req.getParameter("year");
        }else{
            year = Integer.valueOf(CommonUtil.getCurrentYear()).toString();
        }

    
        List data = this.kecelakaanKerjaDao.getAllByYear(year);
        
        map.addAttribute("data", data);
        map.addAttribute("minYear", CommonUtil.getCurrentYear()-3);
        map.addAttribute("maxYear", CommonUtil.getCurrentYear()+3);
        map.addAttribute("currentYear", year);

    }



    @RequestMapping("/view-mould-foundry-data.htm")
    public void viewMouldFoundryData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='mouldfoundry' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-tps-mould-pms-data.htm")
    public void viewTPSMouldPMSData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='mouldpms' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-tps-mould-2ml-data.htm")
    public void viewTPSMould2mlData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='mould2ml' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-tps-mould-shaft2w-data.htm")
    public void viewTPSMouldShaft2WData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='shaft2w' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-tps-mould-shaft4w-data.htm")
    public void viewTPSMouldShaft4WData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='shaft4w' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-tps-machining1-data.htm")
    public void viewTPSMachining1Data(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='machining1' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-tps-machining2-data.htm")
    public void viewTPSMachining2Data(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='machining2' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-tps-mould-sm60-data.htm")
    public void viewTPSMouldSM60Data(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='mouldsm60' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-tps-mould-disa-data.htm")
    public void viewTPSMouldDisaData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='moulddisa' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-operation-machining-data.htm")
    public void viewOperationMCData(ModelMap map,HttpServletRequest req){
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String id = req.getParameter("id");

        String query= "from AvgMoulding where date between '"+start+"' and '"+end+"' and type ='operation-mc' order by date desc";
        if(id != null ){
            AvgMoulding am = new AvgMoulding();
            am.setId(Long.parseLong(id));
            this.avgMouldingDao.delete(am);

            map.addAttribute("msg","Data has been deleted");

        }
        List data = this.avgMouldingDao.getAll(query);
        map.addAttribute("data", data);
        map.addAttribute("start", start);
        map.addAttribute("end", end);
    }

    @RequestMapping("/view-rekap-kecelakaan-kerja-data.htm")
    public void viewRekapKecelakaanKerja(ModelMap map,HttpServletRequest req){

        int curYear = CommonUtil.getCurrentYear();

        List<RekapKecelakaanKerja> data = this.rekapKecelakaanKerjaDao.getAll("from RekapKecelakaanKerja");

        List data2 = this.kecelakaanKerjaDao.custom("SELECT sum(total) FROM KecelakaanKerja where YEAR(MONTH)="+curYear);

        String tahunini = data2.get(0).toString();

        map.addAttribute("lalu5", data.get(0).getLalu5());
        map.addAttribute("lalu4", data.get(0).getLalu4());
        map.addAttribute("lalu3", data.get(0).getLalu3());
        map.addAttribute("lalu2", data.get(0).getLalu2());
        map.addAttribute("lalu1", data.get(0).getLalu1());
        map.addAttribute("id",data.get(0).getId());
        map.addAttribute("tahunini",tahunini);



    }

   @RequestMapping("/view-rekap-kecelakaan-kerja-graph.htm")
    public void viewRekapKecelakaanKerjaGraph(ModelMap map,HttpServletRequest req){

        int curYear = CommonUtil.getCurrentYear();

        List<RekapKecelakaanKerja> data = this.rekapKecelakaanKerjaDao.getAll("from RekapKecelakaanKerja");

        List data2 = this.kecelakaanKerjaDao.custom("SELECT sum(total) FROM KecelakaanKerja where YEAR(MONTH)="+curYear);

        String tahunini = data2.get(0).toString();

        map.addAttribute("lalu5", data.get(0).getLalu5());
        map.addAttribute("lalu4", data.get(0).getLalu4());
        map.addAttribute("lalu3", data.get(0).getLalu3());
        map.addAttribute("lalu2", data.get(0).getLalu2());
        map.addAttribute("lalu1", data.get(0).getLalu1());
        map.addAttribute("tahunini",tahunini);

    }

   @RequestMapping("/view-tapping-graph.htm")
   public void viewTPSTappingGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='tapping' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='tapping' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }
   
   @RequestMapping("/view-cnc-graph.htm")
   public void viewTPSCNCGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='cnc' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='cnc' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }


   @RequestMapping("/view-tps-machining1-graph.htm")
   public void viewTPSMachining1Graph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='machining1' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='machining1' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }


   @RequestMapping("/view-tps-machining2-graph.htm")
   public void viewTPSMachining2Graph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='machining2' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='machining2' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-machining-comp-graph.htm")
   public void viewTPSMCCompGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='mccomp' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='mccomp' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-machining-p1-graph.htm")
   public void viewTPSMCP1Graph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='mcp1' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='mcp1' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-mould-foundry-graph.htm")
   public void viewMouldFoundryGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='mouldfoundry' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='mouldfoundry' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-tps-mould-pms-graph.htm")
   public void viewTPSMouldPMSGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='mouldpms' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='mouldpms' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-tps-mould-sm60-graph.htm")
   public void viewTPSMouldSM60Graph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='mouldsm60' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='mouldsm60' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-tps-mould-disa-graph.htm")
   public void viewTPSMouldDisaGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='moulddisa' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='moulddisa' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-tps-mould-2ml-graph.htm")
   public void viewTPSMould2mlGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='mould2ml' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='mould2ml' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-tps-mould-shaft2w-graph.htm")
   public void viewTPSMouldShaft2wGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='shaft2w' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='shaft2w' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-tps-mould-shaft4w-graph.htm")
   public void viewTPSMouldShaft4wGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='shaft4w' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='shaft4w' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }

   @RequestMapping("/view-operation-machining-graph.htm")
   public void viewTPSOperationMCGraph(ModelMap map,HttpServletRequest req){
       this.startDate = req.getParameter("start");
       this.endDate = req.getParameter("end");


       map.addAttribute("start", startDate);
       map.addAttribute("end", endDate);


       int avgStartMonth=0;
        int avgEndMonth=0;
        String avgStartDate="";
        String avgEndDate="";

        if(MainController.startDate != null){


        String tempDate[] = MainController.startDate.split("-");
        if((Integer.parseInt(tempDate[1]) - 3) <=0){
           if ((Integer.parseInt(tempDate[1])-3) == 0){

                avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "12";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];

           }
           else if ((Integer.parseInt(tempDate[1])-3) == -1){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "11";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-1");
           }
           else if ((Integer.parseInt(tempDate[1])-3) == -2){
               avgEndMonth = Integer.parseInt(tempDate[1]);
                avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
                tempDate[0] = String.valueOf(Integer.parseInt(tempDate[0])-1);
                tempDate[1] = "10";
                avgStartMonth = Integer.parseInt(tempDate[1]);
                avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
               System.out.println("bulan=-2");
           }

        }
        else{
            avgStartMonth= Integer.parseInt(tempDate[1]) - 3;
            avgEndMonth = Integer.parseInt(tempDate[1]);
            avgStartDate = tempDate[0]+"-"+avgStartMonth+"-"+tempDate[2];
            avgEndDate = tempDate[0]+"-"+avgEndMonth+"-"+tempDate[2];
        }
        }

       String query= "from AverageMoulding where date between '"+avgStartDate+"' and '"+avgEndDate+"' and type ='operation-mc' order by date asc";
       List data = this.averageMouldingDao.getAll(query);
       map.addAttribute("data", data);

       String query2 ="from AvgMoulding where date between '"+this.startDate+"' and '"+this.endDate+"' and type ='operation-mc' order by date asc";
       List data2 = this.avgMouldingDao.getAll(query2);
       map.addAttribute("data2", data2);
    }
}
